package com.ssy.lingxi.order.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 订单优惠券使用记录
 * @author 万宁
 * @version 2.0.0
 * @date 2021-09-23
 */
@Entity
@Table(schema = "public", name = "ord_coupon", indexes = {@Index(name = "ord_coupon_order_id_idx", columnList = "order_id")})
public class OrderCouponDO implements Serializable {
    private static final long serialVersionUID = -277025122303842994L;

    /**
     * 主键Id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ord_coupon_seq")
    @SequenceGenerator(sequenceName = "ord_coupon_seq", name = "ord_coupon_seq", allocationSize = 1)
    private Long id;

    /**
     * 多对一双向关联订单
     */
    @JsonBackReference
    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "order_id")
    private OrderDO order;

    /**
     * （营销服务）优惠券Id
     */
    @Column
    private Long couponId;

    /**
     * 优惠券名称
     */
    @Column(columnDefinition = "varchar(60)")
    private String name;

    /**
     * 优惠券类型，定义在 MerchantCouponTypeEnum 或 PlatformCouponTypeEnum 中，需要根据 belongType 进行判断
     */
    @Column
    private Integer couponType;

    /**
     * 优惠券归属类型，定义在 BelongTypeEnum 中
     */
    @Column
    private Integer belongType;

    /**
     * 优惠券面额
     */
    @Column(columnDefinition = "numeric")
    private BigDecimal amount;

    /**
     * 优惠券有效期起始时间
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime startTime;

    /**
     * 优惠券有效期结束时间
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime expireTime;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public OrderDO getOrder() {
        return order;
    }

    public void setOrder(OrderDO order) {
        this.order = order;
    }

    public Long getCouponId() {
        return couponId;
    }

    public void setCouponId(Long couponId) {
        this.couponId = couponId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getCouponType() {
        return couponType;
    }

    public void setCouponType(Integer couponType) {
        this.couponType = couponType;
    }

    public Integer getBelongType() {
        return belongType;
    }

    public void setBelongType(Integer belongType) {
        this.belongType = belongType;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public LocalDateTime getStartTime() {
        return startTime;
    }

    public void setStartTime(LocalDateTime startTime) {
        this.startTime = startTime;
    }

    public LocalDateTime getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(LocalDateTime expireTime) {
        this.expireTime = expireTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        OrderCouponDO that = (OrderCouponDO) o;
        return Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
